import {defineStore} from 'pinia'
import {ref} from "vue"
import {adminInfoAPI} from "@/api/AdminApi/admin.js";

export const useAdminStore = defineStore('admin', () => {
    const adminInfo = ref({})
    const token = ref('')
    const setToken = (newToken) => {
        token.value = newToken
    }
    const removeToken = () => {
        token.value = ''
    }
    const setAdminInfo = (newAdminInfo) =>{
        adminInfo.value = newAdminInfo
    }
    const clearAdminInfo = () => {
        adminInfo.value = {}
    }
    const getAdminInfo = async () => {
        const res = await adminInfoAPI() //请求获取数据
        adminInfo.value = res.data
    }
    return {
        token,
        setToken,
        removeToken,
        adminInfo,
        setAdminInfo,
        clearAdminInfo,
        getAdminInfo
    }
}, {
    persist: true
})
